﻿using ConfExpert.Forms.Araclar;
using ConfExpert.Forms.IT;
using ConfExpert.Forms.Sistem;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevTeamIT;
using ITaskManager.Forms.IT;
using ITaskManager.Properties;
using System;
using System.Drawing;


namespace ConfExpert.Utility.Ribbon
{
    public class ConfExpertRibbon
    {
        public static int[] TeamLeaders = new int[] { 3, 16, 22, 26, 7, 13, 11 };

        public class Departman
        {
            public const int KumasDepo = 6;
            public const int AksesuarSatinalma = 2;
        }

        public static RibbonManager rm;
        public static void Init()
        {
            RibbonControl RibbonControl = AppSession.MainForm.Ribbon;
            RibbonControl.Pages.Clear();
            Image newIcon = Resources.promotion;
            Image listIcon = Resources.TableHS;

            rm = new RibbonManager(RibbonControl);
            rm.MenuClicked += RibbonManager_MenuClicked;
            RibbonManager.Page page;
            RibbonManager.Group group;
            RibbonManager.Menu menu;
            RibbonManager.SubMenu subMenu;

            #region Ana Sayfa
            page = rm.AddPage(RibbonControl, "Ana Sayfa");
            group = page.AddGroup("Araçlar");

            if (Session.isDeveloper)
                group.AddMenu("Exception İnceleme", Resources.Sign_Error_icon5, typeof(ExceptionViewer));

            group.AddMenu("Döviz Kurları", Resources.US_dollar, typeof(TCMB));

            //group.AddMenu("Profil Gönder", Resources.mail_send, typeof(Profil));

            menu = group.AddMenu("Refresh Lookups", Resources.refresh);
            menu.AddCustomAction(AppSession.MainForm.RefreshData);

            //            group.AddMenu("Müşteri", Resources.XtraVerticalGrid_EnlargedSmallIcon, typeof(Customer)).SetVisibleFor(47);

            //menu = group.AddMenu("Coverage", Resources.down, typeof(Coverage));
            //menu.SetVisibleFor(17);


            menu = group.AddMenu("Pencereler", Resources.ParametersLarge);
            menu.BeginGroup();

            subMenu = menu.AddSubMenu("Diğerlerini Kapat", Resources.WatermarkLarge_16);
            subMenu.AddCustomAction(AppSession.MainForm.DigerleriniKapat);

            subMenu = menu.AddSubMenu("Hepsini Kapat", Resources.delete_16);
            subMenu.AddCustomAction(AppSession.MainForm.HepsiniKapat);

            //menu = group.AddMenu("Müşteri Bazlı İşlemler", Resources.Login_Manager);
            //menu.AddCustomAction(MusteriBazli);
            //menu.BeginGroup();

            //menu = group.AddMenu("Sezon Bazlı İşlemler", Resources.Actions_flag_red_icon);
            //menu.AddCustomAction(SezonBazli);
            //menu.SetVisibleFor(5);

            //menu = group.AddMenu("Üretici Bazlı İşlemler", Resources.Import);
            //menu.AddCustomAction(AppSession.MainForm.UreticiBazliIslemler);

            //menu = group.AddMenu("Raporlar", Resources.report);
            //menu.AddCustomAction(Raporlar);



            #endregion

            #region Sistem

            page = rm.AddPage(RibbonControl, "Sistem");
            group = page.AddGroup("Varlıklar");

            //group.AddMenu("TableScope", Resources.right, typeof(Scope)).SetVisibleFor(17);
            //group.AddMenu("Generic Reports", Resources.report, typeof(R));  //.SetVisibleFor(17);
            group.AddMenu("Yetki", Resources.Highlight_32x32, typeof(Yetki)).SetVisibleFor(17);
            group.AddMenu("Lookup Map", Resources.refresh_241, typeof(LookupMap)).Hide();
            group.AddMenu("Excel View", Resources.Highlight_32x32, typeof(ExcelView)).Hide();
            group.AddMenu("Temel Tablolar", Resources.Highlight_32x32, typeof(Repository)).Hide();
            //group.AddMenu("Özellikler", Resources.iMac, typeof(Lookups)).Hide();

            //menu = group.AddMenu("Üreticiler", Resources.factory, typeof(Vendor));
            //menu.SetVisibleForUsers(TeamLeaders);
            //menu.BeginGroup();

            //group.AddMenu("Müşteriler ve Markalar", Resources.BO_Customer_Large, typeof(Customers)).SetVisibleForUsers(TeamLeaders);
            //group.AddMenu("Atölyeler", Resources.Devices_media_flash_sd_mmc_icon, typeof(Repository), "Atelye").SetVisibleForUsers(TeamLeaders);


            menu.BeginGroup();

            //group.AddMenu("Roller ve Yetkiler", Resources.BO_User_Large, typeof(Yetki)).Hide();

            //group = page.AddGroup("Customization");
            //group.AddMenu("Forms", Resources.down, typeof(ConfExpert.Forms.Sistem.Forms)).Hide();
            //group.AddMenu("Grids", Resources.axes, typeof(CustomizeGrids)).Hide();
            //group.AddMenu("Lookups", Resources.BO_User_Large, typeof(CustomizeLookUps)).Hide();

            group = page.AddGroup("Helpers");
            //group.AddMenu("Generate Data", new Bitmap(listIcon), typeof(TestWithData)).Hide();
            //group.AddMenu("Exceptions", new Bitmap(listIcon), typeof(Exceptions)).Hide();
            //menu = group.AddMenu("Non-classified", new Bitmap(listIcon));
            //menu.SetVisibleForUsers(Admins);
            //menu.AddSubMenu("Read Fabric Scans", new Bitmap(listIcon), typeof(Fabrics));
            //TODO menu.AddSubMenu("GDI+", new Bitmap(listIcon), typeof());

            group.AddMenu("Usage Graph", Resources.Caramel___48x48, typeof(WhosOnline), 1).Hide();
            group.AddMenu("Usage Graph ConfOrder", Resources.Caramel___48x48, typeof(WhosOnline), 2).Hide();
            group.AddMenu("Online Users", Resources.SNP_2696434_en_v1, typeof(OnlineUsers)).Hide();
            group.AddMenu("Screenshots", Resources.Computer_On, typeof(Screenshots)).Hide();

            #endregion

            #region Yardım

            /*
            #region Yardım
            page = AddPage(RibbonControl, "Yardım");
            group = page.AddGroup("Yardım");

            menu = group.AddMenu("Versiyon Geçmişi", Resources.CustomDraw_Icon, typeof(VersiyonGecmis));
            //menu = group.AddMenu("Yardım", Resources.support_icon, typeof());
            #endregion
            */

            #endregion

            #region Bilgiİşlem

            page = rm.AddPage(RibbonControl, "Bilgi İşlem").SetVisibleFor(194);
            group = page.AddGroup("Ana");

            menu = group.AddMenu("Fatura Yönetimi", Resources.purchase_order32).SetVisibleFor(204);
            menu.AddSubMenu("Edit", newIcon, typeof(Fatura)).SetVisibleFor(204);
            menu.AddSubMenu(true, "Pivot Görünüm", null, typeof(FaturaPivot)).SetVisibleFor(204);
            menu.AddSubMenu("Denormalize Görünüm", null, typeof(DenormalizeFatura)).SetVisibleFor(204);

            //menu = group.AddMenu("Envanter", Resources.display).SetVisibleFor(194);
            //menu.AddSubMenu("Notebook ve Desktop Envanter Ekleme", newIcon, typeof(ConfExpert.Forms.IT.NotebookDesktopEnvanter));
            //menu.AddSubMenu("Sunucu ve Aktif Cihazlar Envanter Ekleme", newIcon, typeof(ConfExpert.Forms.IT.));
            //menu.AddSubMenu("Yazıcı Envanter Ekleme", newIcon, typeof(ConfExpert.Forms.IT.TelefonListesi));
            group.AddMenu("Envanter", Resources.iMac, typeof(ConfExpert.Forms.IT.EnvanterEkle)).SetVisibleFor(194);
            group.AddMenu("Sunucu ve Aktif Cihazlar", Resources.BO_Product_Large, typeof(ConfExpert.Forms.IT.SunucuAktifCihazlar)).SetVisibleFor(216);
            group.AddMenu("Servis Takip", Resources.truck1, typeof(ServisTakip)).SetVisibleFor(204);

            group.AddMenu("Şirket Kartları", Resources.BO_Contact_Large, typeof(ConfExpert.Forms.IT.SirketKartBilgisi)).Hide();

            menu = group.AddMenu("Takipler", Resources.Find_32x32).SetVisibleFor(241);
            menu.AddSubMenu("Araç Takip", newIcon, typeof(ConfExpert.Forms.IT.AracTakipListesi)).SetVisibleFor(204);
            //menu.AddSubMenu("Infomobil (test)", newIcon, typeof(Infomobil)).SetVisibleFor(204);
            menu.AddSubMenu("Telefon Takip", newIcon, typeof(ConfExpert.Forms.IT.TelefonListesi)).SetVisibleFor(204);
            menu.AddSubMenu("Hat Devre Takip", newIcon, typeof(ConfExpert.Forms.IT.HatDevreListesi)).SetVisibleFor(241);


            group = page.AddGroup("Yardımcı");
            //RibbonManager.Menu s2 = group.AddMenu("Şirket.Belirle", Resources.axes);
            //s2.AddCustomAction(SetSirket);

            menu = group.AddMenu("Parametreler", Resources.MenuBar_ChooseSkin_Large).SetVisibleFor(194);
            menu.AddSubMenu("Şirket", newIcon, typeof(Repository), "Sirket");
            menu.AddSubMenu("Tedarikçi", newIcon, typeof(Repository), "Tedarikci");
            menu.AddSubMenu("Fatura Tipi", newIcon, typeof(Repository), "IT_FaturaTipi");
            menu.AddSubMenu("Lokasyon", newIcon, typeof(ConfExpert.Forms.IT.IT_Lokasyon));
            menu.AddSubMenu("Alan İsimleri", newIcon, typeof(ConfExpert.Forms.IT.Alan));
            menu.AddSubMenu("Cihaz Tipleri", newIcon, typeof(ConfExpert.Forms.IT.CihazTipi));
            //menu.AddSubMenu("Personel", newIcon, typeof(ITaskManager.Forms.IT.Employees));

            //group.AddMenu("", Resources.MenuBar_ChooseSkin_Large, typeof(ConfExpert.Forms.IT.SetSirket));
            //group.AddMenu("Fatura Aktar", Resources.MenuBar_ChooseSkin_Large, typeof(ConfExpert.Forms.IT.ImportFatura)).SetVisibleFor(204);
            group.AddMenu("Personel", Resources.BO_Contact_Large, typeof(ITaskManager.Forms.IT.Employees)).SetVisibleFor(204);

            #endregion



            foreach (RibbonPage ribbonPage in RibbonControl.Pages)
            {
                foreach (RibbonPageGroup ribbonGroup in ribbonPage.Groups)
                {
                    ribbonGroup.Visible = false;
                    foreach (object ribbonMenu in ribbonGroup.ItemLinks)
                    {
                        if (ribbonMenu is BarButtonItemLink)
                            if (((BarButtonItemLink)ribbonMenu).Visible)
                            {
                                ribbonGroup.Visible = true;
                                break;
                            }
                    }
                }

                if (ribbonPage.Visible)
                {
                    ribbonPage.Visible = false;
                    foreach (RibbonPageGroup ribbonGroup in ribbonPage.Groups)
                    {
                        if (ribbonGroup.Visible)
                        {
                            ribbonPage.Visible = true;
                            break;
                        }
                    }
                }
            }

            RibbonControl.ForceInitialize();
        }



        static void RibbonManager_MenuClicked(Type type, params object[] parameters)
        {
            AppSession.MainForm.ShowMdiChildForm(type, parameters);
        }




        public static void Raporlar()
        {
            AppSession.MainForm.ShowDockPanel("Raporlar");
        }

        public static void SezonBazli()
        {
            AppSession.MainForm.ShowDockPanel("Sezon Bazlı İşlemler");
        }

        public static void MusteriBazli()
        {
            AppSession.MainForm.ShowDockPanel("Müşteri Bazlı İşlemler");
        }


        private static void SetSirket()
        {
            using (SetSirket s = new SetSirket())
                s.ShowDialog();
        }


    }
}